<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/6
 * Time: 23:30
 */

namespace app\api\controller\v1;

use app\api\model\Member as MemberModel;
use app\api\model\Integral as IntegralModel;
use app\api\model\Recharge as RechargeModel;
use app\api\model\Goodsorder as GoodsorderModel;
use app\api\model\Account as AccountModel;

use think\Exception;
use think\Log;
use think\Request;
use think\Session;
use app\api\controller\BaseController;
use app\api\model\Integral;
use app\api\model\Recharge;
use app\api\model\Goodsorder;
use app\common\model\RewardModel;

class Account extends  BaseController
{
    public function index(){
		$mid = $this->getLoginId();
		if(empty($mid)){
			return json(["returnCode"=>-7,"returnMsg"=>"请登录!","data"=>""]);exit;
		}
		
		$member = MemberModel::selectOneMemberByID($mid);
		
		$ketiqu = $member['rewardaccount'];//
		$buketiqu = $member['account'];//余额,不可提取
		$dongjie = $member['account_lock'] + $member['rewardaccount_lock'];
		//总资产 余额 + 可提现(奖励) + 提现锁定 + 订单锁定  
		$zong = $member['account'] + $member['rewardaccount'] ;
		
		$data = [];
		$data['zong'] = $zong;
		$data['buketiqu']= $buketiqu;
		$data['ketiqu']= $ketiqu;
		$data['dongjie']= $dongjie;
		
		//所有奖励
		$jingliWhere = [
		    'mid'=>$mid,
		];
		$jiangli = RewardModel::instance()->where($jingliWhere)->sum('money');
		
		//订单金额
		$orderMap = [
		    'mid'=>$mid,
		    'ispay'=>[['=',1],['=',3],['=',5],'or']
		];
		$orderprice = Goodsorder::instance()-> where($orderMap)->sum('total');
		
		/**充值总金额**/
		$rechargeMap = ['type' => 1,'mid' => $mid,'ifpass' => 1];
		$chongzhi = Recharge::instance()->where($rechargeMap)->sum('money');
		$data['chongzhi']=$chongzhi;
		
		/**提现总金额**/
		$withdrawMap = ['type' => 2,'mid' => $mid,'ifpass' => 1];;
		$tixian = Recharge::instance()->where($withdrawMap)->sum('money');
		$data['tixian']=$tixian;
		
		/**历史总流入**/
		/**所有奖励、所有充值**/
		$data['zongliuru']= $jiangli + $chongzhi;
		
		/**历史总流出**/
		/**提现 + 支付**/
		$data['zongliuchu']= $tixian + $orderprice;
		$data = array("returnCode"=>1,"returnMsg"=>"success!", 'data' => $data);
		return json($data);
	}
	
	/**
	 * 提现列表
	 */
	public function withdraw_list(){
	    
	}
	
	
}